<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.orderNo" :placeholder="$t('message.orderNo')" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.email" :placeholder="$t('message.email')" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{$t('message.search')}}</el-button>
        <el-button @click="clearQueryData()">{{$t('message.clean')}}</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="center"
        :label="$t('message.orderNo')">
      </el-table-column>
      <!--<el-table-column
        prop="company"
        header-align="center"
        align="center"
        label="所属公司">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="客户名称">
      </el-table-column>-->
      <el-table-column
        prop="userEmail"
        header-align="center"
        align="center"
        :label="$t('message.userEmail')">
      </el-table-column>
      <el-table-column
        prop="phone"
        header-align="center"
        align="center"
        :label="$t('message.phoneNo')">
      </el-table-column>
      <!--<el-table-column
        prop="discountPrice"
        header-align="center"
        align="center"
        label="刀片数">
      </el-table-column>
      <el-table-column
        prop="saleAmount"
        header-align="center"
        align="center"
        label="膜数">
      </el-table-column>
      <el-table-column
        prop="stock"
        header-align="center"
        align="center"
        label="机器数">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="次数">
      </el-table-column>-->
      <el-table-column
        prop="remark"
        header-align="center"
        align="center"
        :label="$t('message.remark')">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        :label="$t('message.receiver')">
      </el-table-column>
      <el-table-column
        prop="phone"
        header-align="center"
        align="center"
        :label="$t('message.receiverPhone')">
      </el-table-column>
      <el-table-column
          prop="status"
          header-align="center"
          align="center"
          :label="$t('message.status')">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1" size="small">{{$t('message.noConfirm')}}</el-tag>
          <el-tag v-else-if="scope.row.status === 2" size="small" type="success">{{$t('message.confirmed')}}</el-tag>
          <el-tag v-else-if="scope.row.status === 3" size="small" type="success">{{$t('message.shipped')}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        :label="$t('message.createTime')">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="200"
        :label="$t('message.operation')">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="queryDetailHandle(scope.row.id)">{{$t('message.read')}}</el-button>
          <el-button type="text" size="small" v-show="scope.row.status === 1" @click="updateHandle(scope.row.id,2)" >{{$t('message.confirm')}}</el-button>
          <el-button type="text" size="small" v-show="scope.row.status === 2" @click="shipHandle(scope.row.id)" >{{$t('message.ship')}}</el-button>
          <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">{{$t('message.del')}}</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
    <query-detail v-if="queryDetailVisible" ref="queryDetail" @refreshDataList="getDataList"></query-detail>
    <ship-order v-if="shipVisible" ref="shipOrder" @refreshDataList="getDataList"></ship-order>
    <!-- <addGoods v-if="addVisible" ref="addGoods" @refreshDataList="getDataList"></addGoods> -->


    <!-- <el-dialog
      :title="dataForm.status==2 ? $t('message.confirm') : $t('message.reject') "
      :visible.sync="confirmDialogVisible"
      width="50%">
      <div slot="title" v-if="dataForm.status==2">{{$t('message.submit')}}</div>
      <div slot="title" v-else-if="dataForm.status!=2">{{$t('message.reject')}}</div>
      <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="confirmSubmit()" label-width="100px">
        <el-input v-if="false" prop="id" v-model="dataForm.id"></el-input>
        <el-form-item :label="$t('message.comment')" prop="comment">
          <el-input type="textarea" v-model="dataForm.comment" :placeholder="$t('message.comment')" :rows="5"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="confirmDialogVisible = false">{{$t('message.cancle')}}</el-button>
        <el-button type="primary" @click="confirmSubmit()">{{$t('message.submit')}}</el-button>
      </span>
    </el-dialog> -->
  </div>
</template>

<script>
  import QueryDetail from './appuser-purchase-info-detail'
  import ShipOrder from './appuser-ship-order'

  export default {
    data () {
      return {
        dataForm: {
          id: '',
          status: '',
          comment: '',
          orderNo: '',
          email: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        queryDetailVisible: false,
        addVisible: false,
        shipVisible: false,
        confirmDialogVisible: false
      }
    },
    components: {
      QueryDetail,
      ShipOrder
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/sys/purchaseOrder/list'),
          method: 'POST',
          data: this.$http.adornData({
            'currPage': this.pageIndex,
            'limit': this.pageSize,
            'orderNo': this.dataForm.orderNo,
            'email': this.dataForm.email
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 查看详情
      queryDetailHandle (val) {
        this.queryDetailVisible = true
        this.$nextTick(() => {
          this.$refs.queryDetail.init(val)
        })
      },
      shipHandle (val) {
        this.shipVisible = true
        this.$nextTick(() => {
          this.$refs.shipOrder.init(val)
        })
      },
      updateHandle (orderId, status) {
        this.$http({
          url: this.$http.adornUrl('/sys/purchaseOrder/updateOrderStatus'),
          method: 'post',
          data: this.$http.adornData({
            'orderId': orderId,
            'status': status
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: this.$t('message.success'),
              type: 'success',
              duration: 300,
              onClose: () => {
                this.visible = false
                this.getDataList()
              }
            })
          } else {
            this.$message.error(this.$t('message.failure'))
          }
        })
      },
      // 查看 / 修改
      addOrUpdateHandle (id, op) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, op)
        })
      },
      clearQueryData () {
        this.dataForm.orderNo = ''
        this.dataForm.email = ''
        this.getDataList()
      }
    }
  }
</script>
